package g2RedBlackTree;

public abstract class RedBlackTreeData<T1> extends MyRedBlackTree<T1> {
	

	//private RedBlackNode<T1,DataTTree > header;
	

	/**
	 * Construct the tree.
	 */
	public RedBlackTreeData(){
		header = null;
	}
	public RedBlackTreeData(T1 key) {
		header      = new RedBlackNodeData<T1, DataTTree >(key);
		header.left = header.right = null;
	}
	
	/**
	 * Insert into the tree.
	 * @param item the item to insert.
	 * @throws DuplicateItemException if item is already present.
	 */
	@Override
	public RedBlackNodeData<T1,DataTTree > insert(T1 key) {
		@SuppressWarnings("unchecked")
		RedBlackNodeData<T1,DataTTree > result = (RedBlackNodeData<T1,DataTTree >)insertMe(key);
		return result;
	}
	/**
	 * Remove from the tree.
	 * @param x the item to remove.
	 * @throws UnsupportedOperationException if called.
	 */
	public void remove( int x ) {
		throw new UnsupportedOperationException( );
	}

	/**
	 * Print all items.
	 */
	@SuppressWarnings("unchecked")
	public void printTree( ) {
		System.out.println("root["+header.sequenceNumber+"]");
		printTree( (RedBlackNodeData<T1, DataTTree > )header );
		
	}

	/**
	 * Internal method to print a subtree in sorted order.
	 * @param t the node that roots the tree.
	 */
	@SuppressWarnings("unchecked")
	private void printTree( RedBlackNodeData<T1, DataTTree > t ) {
		if( t != null ) {
			
			//System.out.print(t.sequenceNumber +"C:{"+ ((t.color==RED)?"R":"B") + "}L[");
			System.out.print(t.sequenceNumber+"["+ ((t.color==RED)?"R":"B") + "]" + "==>");
			printTree( ( RedBlackNodeData<T1, DataTTree >)t.left);
            System.out.print("]" + ";");
			
			
			
			
				//for (String word : t.wordsAplhabeticOrdered) {
				//	System.out.print( word + ";");
				//}
			//System.out.print(t.wordsAplhabeticOrdered.toString());
			
			
            //System.out.print(t.sequenceNumber +"C:{"+ ((t.color==RED)?"R":"B") + "}R[");
            System.out.print(t.sequenceNumber+"["+ ((t.color==RED)?"R":"B") + "]" + "==>");
            printTree( ( RedBlackNodeData<T1, DataTTree >)t.right);
            System.out.println("]" + ";");
		}
	}

	

	

	// main test 
    //public static void main( String [ ] args ) {
    //    RedBlackTree t = new RedBlackTree( );
    //    
    //    RedBlackNode redblack = new RedBlackNode(4);
    //    redblack.addWord("avant insertion");
    //    t.insert(redblack);
    //    t.find(4).addWord("apres inserttion");
    //    //t.printTree();
    //}
}
